package top.wuyang.springboot3.schoolTimetable.controller;


import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.wuyang.springboot3.base.PageBean;
import top.wuyang.springboot3.base.R;
import top.wuyang.springboot3.schoolTimetable.entity.TbClassInfo;
import top.wuyang.springboot3.schoolTimetable.service.TbClassInfoService;
import top.wuyang.springboot3.validate.CommonValidate;
import top.wuyang.springboot3.vo.PageVO;

@RestController
@RequestMapping("/classInfo")
@RequiredArgsConstructor
public class TbClassInfoController  {
    private final TbClassInfoService tbClassInfoService;

    @GetMapping("/{pn}/{ps}")
    public R<PageVO<TbClassInfo>> query(TbClassInfo tbClassInfo, @PathVariable("pn") Long pageNumber, @PathVariable("ps") Long pageSize) {
        return tbClassInfoService.query(tbClassInfo, PageBean.instance(pageNumber, pageSize));
    }

    @GetMapping("/{id}")
    public R<TbClassInfo> queryById(@PathVariable("id") Integer id) {
        return tbClassInfoService.queryById(id);
    }

    @PostMapping("")
    public R<String> insert(@RequestBody @Validated(CommonValidate.Add.class) TbClassInfo tbClassInfo) {
        return tbClassInfoService.insert(tbClassInfo);
    }

    @PutMapping("")
    public R<String> update(@RequestBody @Validated(CommonValidate.Edit.class) TbClassInfo tbClassInfo) {
        return tbClassInfoService.update(tbClassInfo);
    }

    @DeleteMapping("/{id}")
    public R<String> delete(@PathVariable("id") Integer id) {
        return tbClassInfoService.delete(id);
    }

}
